package 力扣日常刷题.木22二月.第02天207;

import java.util.Arrays;

/**
 * @author 帅小伙
 * @date 2022/2/7
 * @description
 */
public class Demo27贪心数组拆分1 {

    public int arrayPairSum(int[] nums) {
        Arrays.sort(nums);
        int ans = 0;
        int index = nums.length - 2;
        int round = nums.length/2;
        for (int i = 0; i < round; i++) {
            ans += nums[index];
            index -= 2;
        }
        return ans;
    }
}
